#include "../HLoginPanel.h"
#include "../../HCustomWidgets/HUICLogin.h"
#include "../HSettingPanel.h"
HLoginPanel::HLoginPanel(QWidget *parent)
    :HFlipableWidget(parent)
{
    initUI();
}

HLoginPanel::~HLoginPanel()
{

}

void HLoginPanel::setWarning(QString strWarning)
{
	m_pwndLogin->setWarning(strWarning);
}

void HLoginPanel::setLoginInfo(QStringList strlstLoginInfo)
{
	if(strlstLoginInfo.count() > 1)
	{
		m_pwndLogin->setUserName(strlstLoginInfo[0]);
		m_pwndLogin->setPassword(strlstLoginInfo[1]);
	}
}


void HLoginPanel::initUI()
{
    QFile file(g_strAppPath + QSSRELATIONPATH + "HLoginPanel.qss");
    QString strQss;
    if(file.open(QIODevice::ReadOnly))
    {
        strQss = file.readAll();
    }
    m_pwndLogin = new HUICLogin(NULL);
    QString strtemp = strQss.arg(g_strAppPath + g_strImageRelationPath);
    m_pwndLogin->setStyleSheet(strtemp);
    m_pwndLogin->setFixedSize(410,490);
   // m_pwndLogin->show();

    m_pwndSetting = new HSettingPanel(NULL);
    m_pwndSetting->setStyleSheet(strtemp);
    m_pwndSetting->setFixedSize(410,490);
    //m_pwndSetting->show();

   // HFlipableWidget *t_pFlipableWidget = new HFlipableWidget(NULL);
    setFrontWidget(m_pwndLogin);
    setBackWidget(m_pwndSetting);

    QObject::connect(m_pwndLogin,SIGNAL(sigSettingButtonClicked()),this,SLOT(sltShowBack()));
    QObject::connect(m_pwndLogin,SIGNAL(sigLoginBtnClicked()),this,SLOT(sltLoginBtnClicked()));
    QObject::connect(m_pwndLogin,SIGNAL(sigMinBtnClicked()),this,SLOT(sltMinBtnClicked()));
    QObject::connect(m_pwndSetting,SIGNAL(sigSaveBtnClicked()),this,SLOT(sltShowFront()));
    QObject::connect(m_pwndSetting,SIGNAL(sigCancelBtnClicked()),this,SLOT(sltShowFront()));
	QObject::connect(m_pwndSetting,SIGNAL(sigMinBtnClicked()),this,SLOT(sltMinBtnClicked()));
	QObject::connect(m_pwndSetting,SIGNAL(sigSaveBtnClicked()),this,SLOT(sltSettingSaved()));
}

void HLoginPanel::sltDealPlatformProtocol()
{

}

void HLoginPanel::sltMinBtnClicked()
{
    this->showMinimized();
}

void HLoginPanel::sltLoginBtnClicked()
{
    QString strUserName = m_pwndLogin->getUserName();
    QString strPassword = m_pwndLogin->getPassword();

    HTUIProtocol uiProtocol;
    uiProtocol.m_mainType = UIPM_Login;
    uiProtocol.m_hashProperty.insert(HEP_USERNAME,QVariant(strUserName));
    uiProtocol.m_hashProperty.insert(HEP_PASSWORD,QVariant(strPassword));
    emit sigSendUIProtocol(uiProtocol);

}

void HLoginPanel::sltSettingSaved()
{
	QString strWarning = m_pwndLogin->getWarning();

	if(strWarning == QString::fromLocal8Bit(WARNINGSTR_ARG))
	{
		m_pwndLogin->setWarning("");
	}
}
